<?php 

require_once  __DIR__ . '/includes/authenticate.php';
include_once './db_bb_connect.php';

?>

<!-- /* ############ BEGIN SELECT SEASON ############## */ -->


<div class="container-fluid">
<div class="row">
<div class="col-lg-3 col-md-3"></div>
<div class="col-lg-6 col-md-6">
  <h2>Add Stats to Database by Totals</h2>

<br><br>

<form method="post" action="" > 

 <select name="season" class="form-control" >
         <option id="selected-season" value="" disabled="disabled" selected="selected">Select a season</option>
<?php

$sql = "SELECT DISTINCT season FROM games ORDER BY season";

$result = $db->query ($sql);

while ($row = $result->fetch_assoc()) {
  $season = $row['season'];

  echo "<option value=\"$season\"> $season </option>";
}
?>
  </select>


</form>
<br>
</div>
<div class="col-lg-3 col-md-3"></div>
</div>
</div>

<!-- /* ############ END SELECT SEASON ############## */ -->

  <div id="addstatscontent"></div>
<!-- /* ############ END ADD STATS ############## */ -->


<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

<script type="text/javascript">
  $("form").on("submit", function(e) {
    postData = $( this ).serialize();
    e.preventDefault();
    callAddStatsPage(postData);
});

$( "select" ).on( "change", function(e) {
  postData = $( this ).serialize();
  callAddStatsPage(postData);
  e.preventDefault();
});

function callAddStatsPage(e, postData){
  $.ajax({
  type: "POST",
  url: "./addstats_bytotals_selectgame.php",
  data: this.postData,
  success: function(data) {
  $("#addstatscontent").html(data);
  }
  }); 
  e.preventDefault();
};


</script>
